<template>
    <div>
       <home-header ></home-header>
       <home-swiper :swiperList='swiperList'></home-swiper>
       <home-icons :iconList='iconList'></home-icons>
       <home-recommend :recommendList='recommendList'></home-recommend>
       <home-weekend :weekendList='weekendList'></home-weekend>
    </div>
</template>

<script>
import homeHeader from './componets/homeHeader'
import homeSwiper from './componets/homeSwiper'
import homeIcons from './componets/homeIcons'
import homeRecommend from './componets/homeRecommend'
import homeWeekend from './componets/homeWeekend'
import axios from 'axios'
import { mapState} from 'vuex'
export default {
    components:{
        homeHeader,homeSwiper,homeIcons,homeRecommend,homeWeekend
    },
    name:'Home',
    data() {
        return {
            lastCity:'',
            swiperList:[],
            iconList:[],
            recommendList:[],
            weekendList:[]
        }
    },
    mounted() {
        this.lastCity=this.city
        this.getHomeInfo()
    },
    activated() {
        if(this.lastCity!==this.city){
            this.getHomeInfo()
            this.lastCity=this.city
        }
    },
    computed: mapState([
        // 映射 this.ciyu 为 store.state.city
        'city'
    ]),
    methods: {
        getHomeInfo(){
            axios.get('/api/index.json?city='+this.city).then(this.getHomeInfoSucc);
        },
        getHomeInfoSucc(result){
            result=result.data
            if(result.ret&&result.data){
                var data=result.data
                this.swiperList=data.swiperList
                this.iconList=data.iconList
                this.recommendList=data.recommendList
                this.weekendList=data.weekendList
            }
        }
    }
}
</script>
<style lang="">
    
</style>